home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / pack / xpkdisk / name.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  87 lines

  1. /*-
  2.  * NAME.C
  3.  *
  4.  * The knowledge of the file names used for tracks.
  5.  *
  6.  * $Id: name.c,v 1.2 1993/11/08 13:18:19 Rhialto Rel $
  7.  * $Log: name.c,v $
  8.  * Revision 1.2  1993/11/08  13:18:19  Rhialto
  9.  * Add RCS tags.
  10.  *
  11.  *
  12.  * This code is (C) Copyright 1993 by Olaf Seibert. All rights reserved.
  13.  * May not be used or copied without a licence.
  14. -*/
  15. #include "xpkdisk.h"
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <ctype.h>
  19.  
  20. extern struct DosLibrary   *DOSBase;
  21. static const char      Subdir[] = "Group_%04x_%c%c";
  22. static const char      File[]    = "Track_%04x_%c%c";
  23.  
  24. #define HASHTABLESIZE    72    /* Must be less than 13*13 */
  25.  
  26. Prototype int Hash(unsigned char *name);
  27.  
  28. int
  29. Hash(unsigned char *name)
  30. {
  31.     int val, len, i;
  32.  
  33.     val = len = strlen(name);
  34.     for (i=0; i<len; i++)
  35.     val = ((val*13) + (int)toupper(*name++)) & 0x7ff;
  36.  
  37.     return val;
  38. }
  39.  
  40. int
  41. HashName(char *filename, char *pattern, int number, int hash)
  42. {
  43.     int         hh;
  44.     int         len;
  45.  
  46.     len = sprintf(filename, pattern, number, 'M', 'M');
  47.     hh = (Hash(filename) - hash) % HASHTABLESIZE;
  48.     filename[--len] -= hh % 13;
  49.     filename[--len] -= hh / 13;
  50.  
  51.     return len + 2;
  52. }
  53.  
  54. Prototype void NewName(char *filename, int track);
  55.  
  56. void
  57. NewName(char *filename, int track)
  58. {
  59.     int         groupd = track / HASHTABLESIZE;
  60.     int         group = groupd * HASHTABLESIZE;
  61.     int         len;
  62.  
  63.     len = HashName(filename, Subdir, group, groupd % HASHTABLESIZE);
  64.     filename += len;
  65.     *filename++ = '/';
  66.     HashName(filename, File, track, track % HASHTABLESIZE);
  67. }
  68.  
  69. Prototype void MakeSubDirs(int mintrack, int maxtrack);
  70.  
  71. void
  72. MakeSubDirs(int mintrack, int maxtrack)
  73. {
  74.     char        dirname[40];
  75.     BPTR        fl;
  76.     int         g;
  77.     int         gd;
  78.  
  79.     for (gd = mintrack / HASHTABLESIZE, g = gd * HASHTABLESIZE;
  80.      g <= maxtrack;
  81.      gd++, g += HASHTABLESIZE) {
  82.     HashName(dirname, Subdir, g, gd % HASHTABLESIZE);
  83.     if (fl = CreateDir(dirname))
  84.         UnLock(fl);
  85.     }
  86. }
  87.